<template>
  <div class="tab">
    <div class="tab-item" v-for="(item, index) in tabData" :key="index" @click="handleTabItemClick(index)" :class="{select:currentTabIndex === index}">{{item.title}}
    </div>
  </div>
</template>

<script>
export default {
  name: 'Tab',
  data () {
    return {
      tabData: [{
        title: '产品列表',
        select: true
      }, {
        title: '养护知识',
        select: false
      }, {
        title: '品牌信息',
        select: false
      }],
      currentTabIndex: 0
    }
  },
  methods: {
    handleTabItemClick (index) {
      this.currentTabIndex = index
      this.$emit('tabClick', { index })
    }
  }
}
</script>

<style scoped>
  .tab{
    width: 95%;
    margin: 10px auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-around;
    height: 50px;
    line-height: 50px;
  }
  .tab-item{
    text-align: center;
    width: 33%;
    color: #999;
  }
  .select{
    border-bottom: 1px solid #541300;
    color: #541300;
  }
</style>
